import Vue from 'vue'
import Router from 'vue-router'
import Index from '../pages/index'
import cookie from '../js/cookie'

Vue.use(Router)

var rout =  new Router({
  mode:'history',
  base:'/auto/',
  routes: [
    {path:'/index',name:'index',component:Index},
    {path:'/',name:'index',component:Index},
  ]
})
export default rout;
//导航守卫
rout.beforeEach((to,from,next)=>{
  const openUrl = ["index"]
  if(openUrl.indexOf(to.name)<0){
    // 判断是否登陆
    var userInfo = cookie.getCookie("userInfo");
    console.log(userInfo)
    if(userInfo){
      next();
    }else {
      next({path:'/login',query:{redirect:to.fullPath}})
    }
  }

  next();
})
